var ADMIN = {
		boxTitleExpand: '',
		boxTitleCollapse: '',
		uploadPath: '/uploads/',
		uploadEmpty: '/css/admin/img/global/no-img.png',
		init:function(){
			ADMIN.settings();
			$('#page-content-left > #inner, #page-content-right > #inner').mCustomScrollbar({
				scrollButtons:{
					enable:false
				},
				scrollInertia:150,
				advanced:{
					updateOnBrowserResize:true, 
					updateOnContentResize:true, 
					autoExpandHorizontalScroll:false 
				}
			});
			$(window).resize(function(){
				ADMIN.settings();
			});
			ADMIN.addUploadPhoto();
			ADMIN.removeUploadPhoto();
			
			ADMIN.setIsDefault();
			ADMIN.initEditor();
		},
		initEditor: function(){
			$('textarea.editor').each(function(){
				CKEDITOR.replace($(this).attr('id'),{
					filebrowserBrowseUrl : '/admin/uploadControl/ckeditor',
				});
			});
		},
		settings:function(){
			$('#page-content-left > #inner').attr('style','height:'+($(window).height()-110)+'px');
			$('#page-content-right > #inner').attr('style','height:'+($(window).height()-110)+'px;width:'+($(window).width()-272)+'px');
			
		},
		initNoneMenu:function(){
			
			ADMIN.addUploadPhoto();
			ADMIN.removeUploadPhoto();
			
			ADMIN.setIsDefault();
			ADMIN.initEditor();
		},
		initMenu:function(){
			$('#page-content-left .box-menu .title').click(function(){
				$(this).next().slideToggle('fast');
				if($(this).attr('class').indexOf('title-unactive')>0){
					$(this).removeClass('title-unactive');
					$(this).attr('title',ADMIN.boxTitleCollapse);
				}else{
					$(this).addClass('title-unactive');
					$(this).attr('title',ADMIN.boxTitleExpand);
				}
			});
		},
		addUploadPhoto: function(){
			$('input.data-checkbox').each(function(){
				if(this.checked){
					$('input#'+$(this).attr('data-name')).val($(this).val());
				}
			});
			$('img.upload-preview').uploadControl({
				file_type: 'jpg|jpeg|png|gif|swf',
				path: 'all',
				language: 'vi',
				max_depth: 0,
				buttons:'upload|select|remove|rename|reload|mkdir|language',
				callback:{
					beforeSelect: function(selectedFile, currentControl){},
					afterSelected: function(selectedFile, currentControl){},
					onClosed: function(selectedFile, currentControl){
						if(selectedFile){
							$('input#'+currentControl.attr('data-id')).val(ADMIN.uploadPath+selectedFile.path);
							$('a.upload-remove').remove();
							var oA = $('<a href="#" class="upload-remove"></a>');
							var arr = selectedFile.path.toString().split('.');
							if(arr.length>=2 && arr[arr.length-1].toString().toLowerCase()=='swf'){
								currentControl.attr('src',ADMIN.uploadEmpty);
								$('div.not-click', currentControl.parent().parent()).parent().remove();
								var pr = currentControl.parent();
								var str = ULTI.printSWF({
									width: '100',
									height: '80',
									path: ADMIN.uploadPath + selectedFile.path,
									flashvars: '',
									wmode: 'transparent',
									divclass: 'not-click'
								});
								var swf = $('<span class="img-item">'+str+'</span>');
								swf.append(oA);
								pr.parent().append(swf);
							}else{
								currentControl.attr('src',ADMIN.uploadPath+selectedFile.path);
								currentControl.parent().append(oA);
							}
							ADMIN.removeUploadPhoto();
						}
					}
				}
			});
			$('img.upload-preview-multi').uploadControl({
				file_type: 'jpg|jpeg|png',
				path: 'all',
				language: 'vi',
				max_depth: 0,
				buttons:'upload|select|remove|rename|reload|mkdir|language',
				callback:{
					beforeSelect: function(selectedFile, currentControl){},
					afterSelected: function(selectedFile, currentControl){},
					onClosed: function(selectedFile, currentControl){
						if(selectedFile){
							var oSpan = $('<span class="img-item"></span>');
							var oInput= $('<input type="hidden" name="'+currentControl.attr('data-name')+'[]" value="'+(ADMIN.uploadPath+selectedFile.path)+'"/>');
							var oImg = $('<img class="upload-preview-multi" src="'+ADMIN.uploadPath+selectedFile.path+'"/>');
							var oA = $('<a href="#" class="upload-remove-multi" title="remove" alt="remove"></a>');
							oSpan.append(oInput);
							oSpan.append(oImg);
							if(currentControl.attr('data-checkbox')){
								var oChk = $('<input type="checkbox" name="'+currentControl.attr('data-checkbox')+'[]" data-name="'+currentControl.attr('data-checkbox-name')+'" class="data-checkbox" value="'+(ADMIN.uploadPath+selectedFile.path)+'" title="set default" alt="set default" />');
								oSpan.append(oChk);
							}
							oSpan.append(oA);
							currentControl.parent().parent().append(oSpan);
							ADMIN.removeUploadPhoto();
							ADMIN.setIsDefault();
						}
					}
				}
			});
		},
		removeUploadPhoto: function(){
			$('a.upload-remove').click(function(){
				var swf = $(this).prev('div.not-click');
				if(swf){
					$('input', swf.parent().parent()).val('');
					swf.parent().remove();
				}else{
					$(this).prev('img').attr('src',ADMIN.uploadEmpty);
					$(this).prev('input').val('');
					$(this).remove();
				}
				return false;
			});
			$('a.upload-remove-multi').click(function(){
				$(this).parent().remove();
				return false;
			});
		},
		setIsDefault: function(){
			$('input.data-checkbox').click(function(){
				$('input.data-checkbox').attr('checked', false);
				$(this).attr('checked', true);
				$('input#'+$(this).attr('data-name')).val($(this).val());
			});
		}
}